package com.littlebee.storysuper.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.littlebee.storysuper.R;
import com.littlebee.storysuper.entry.StorySeriesEntry;
import com.littlebee.storysuper.utils.DateUtils;
import com.littlebee.storysuper.widget.AlwaysMarqueeTextView;
import com.littlebee.storysuper.widget.CircleImageView;
import com.littlebee.storysuper.widget.LeanTextView;
import com.littlebee.storysuper.widget.RoundAngleImageView;

import java.net.URLDecoder;
import java.util.List;

public class CircleGridStoryAdapter extends BaseAdapter {

    private List<StorySeriesEntry> mFiles;
    private LayoutInflater mLayoutInflater;
    private Context mContext;

    public CircleGridStoryAdapter(List<StorySeriesEntry> files, Context context) {
        this.mFiles = files;
        mLayoutInflater = LayoutInflater.from(context);
        this.mContext = context;
    }

    @Override
    public int getCount() {
        if(mFiles==null){
            return 0;
        }else if(mFiles.size()<=9){
            return mFiles.size();
        }else{
            return 9;
        }
    }

    @Override
    public StorySeriesEntry getItem(int position) {

        return mFiles.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = mLayoutInflater.inflate(R.layout.item_gridview_circle_story, parent, false);
            holder.imageView = (RoundAngleImageView) convertView.findViewById(R.id.album_image);
            holder.title=(TextView)convertView.findViewById(R.id.tv_title);
            holder.title_1=(TextView)convertView.findViewById(R.id.tv_title_1);
            holder.title1=(TextView)convertView.findViewById(R.id.tv_title1);
            holder.tv=(TextView)convertView.findViewById(R.id.tv) ;

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        final  StorySeriesEntry entry=mFiles.get(position);
        // 根据屏幕宽度动态设置图片宽高
        holder.title.setText(entry.getStoryseriesname());
        holder.title_1.setText(entry.getStorydescription());
        holder.title1.setText(DateUtils.getTimeString(Long.parseLong(entry.getStoryduration())*1000));
        holder.tv.setText(entry.getStoryserieshotpoint());

        Glide.with(mContext).load(entry.getStoryseriesminiphotourl()).error(R.drawable.corner_photo_default_img).into(holder.imageView);

        return convertView;
    }

    private static class ViewHolder {
        RoundAngleImageView imageView;
        TextView title;
        TextView title_1;
        TextView title1;
        TextView tv;
    }
}
